<?php
/**
 *  Evoca Media Services REST API Implementation
 *
 *  This a generic PHP class that can hook-in to Evoca's Media Services
 *
 *  Author:Jeff Walter
 *  http://www.evoca.com
 *
 *  This code is free, provided AS-IS with no warranty expressed or implied.  Use at your own risk.
 *
 */

require_once "EMS_util.class.php";
require_once "EMS_credentials.class.php";

class EMS_api {

	private $EMS_util = null;

	/**
	 * Constructor: Evoca Media Services REST API implementation
	 */
	public function EMS_api() {
		$this->EMS_util = new EMS_util(EMS_credentials::clientID, EMS_credentials::publicID, EMS_credentials::secretKey);
	}

	/**
	 * Makes a request for the Evoca Playlist Player.  Returns the result of the request in an eac_curl http request object.
	 * 
	 * Some valid methods on the returned object:
	 * getHeaders() - returns an array of the response headers
	 * getLastResult - returns the body of the response (in this case, the HTML required to display the playlist player)
	 * 
	 * @return an eac_curl http object
	 * @param $playername Object the name of the player (a list can be found in the Configuration->Players portion of the EMS website)
	 * @param $context Object[optional] the context to pull files from
	 * @param $filter Object[optional]  a metadata filter (e.g. publish=true)
	 * @param $orderBy Object[optional] an ordering directive (e.g. publishDate;DESC)
	 * @param $maxResults Object[optional] the maximum results to return (defaults to 10 if not specified, but can be no greater than 100)
	 */
	public function get_playlist_player($playername, $context = "/", $filter = null, $orderBy = null, $maxResults = null) {
		$param_array = array();

		if($filter != null)
			$param_array["filter"] = $filter;
		if($orderBy != null)
			$param_array["orderBy"] = $orderBy;
		if($maxResults != null)
			$param_array["maxResults"] = $maxResults;

		$paramstring = $this->EMS_util->generate_query_string($param_array);

		$resourcestring = "/players/audio/flash/$playername/$context$paramstring";

		return $this->EMS_util->ems_get($resourcestring);
	}
}
?>